package com.example.boot.derived.impl;

import com.example.boot.derived.DerivedVariable;
import com.google.common.collect.Sets;

import java.util.Map;
import java.util.Set;

public class BusinessService {
    private DerivedVariable eVariable;

    public void init() {
        Set<String> dependencies = Sets.newHashSet("a", "b", "c"); // 依赖的原子变量ID
        eVariable = new DerivedVariable(dependencies, this::calculateE, new JdbcAtomRepository());
    }

    private double calculateE(Map<String, Double> deps) {
        double a = deps.get("a");
        double b = deps.get("b");
        double c = deps.get("c");
        return (a * b) + Math.sqrt(c);
    }

    public void execute() {
        double result = eVariable.compute(); // 触发计算
    }
}
